package org.keyyond.ms.gateway;

import org.keyyond.ms.gateway.filter.MsCustomFilter;
import org.keyyond.ms.gateway.filter.MsPreRequestLogFilter;
import org.keyyond.ms.gateway.router.MsCustomRouteLocator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
public class MsCustomZuulConfig {
	
	@Autowired
    ZuulProperties zuulProperties;  
    @Autowired  
    ServerProperties server;  
    @Autowired  
    JdbcTemplate jdbcTemplate;  
  
    @Bean
    public MsCustomRouteLocator routeLocator() {  
        MsCustomRouteLocator routeLocator = new MsCustomRouteLocator(this.server.getServletPrefix(), this.zuulProperties);  
        routeLocator.setJdbcTemplate(jdbcTemplate);  
        return routeLocator;  
    }
    
    @Bean
    public MsCustomFilter keyyondCustomFilter(){
    	return new MsCustomFilter();
    }
    
    @Bean
    public MsPreRequestLogFilter msPreRequestLogFilter()
    {
    	return new MsPreRequestLogFilter();
    }
    
    @Bean
	public AlwaysSampler defaultSampler() {
		return new AlwaysSampler();
	}

}
